jQuery(document).ready(function(){	
	//获取专题信息
	querySubjectTopic();
	
	//获取头部轮播图片
	$.ajax({  
		type: "POST",  
        url: 'SiteIndex/querySiteAd.json', 
	    data:{  
	    	  visible:0,
	    	  typeid:5
	    },  		    	     
	    cache:false,  
	    dataType:'json',  
	    success:function(data) { 
	    	if(data!=null && data.length>0){		    	    		
	    		$.each(data,function(idx,obj){
	    			if(obj.filepath!=null && $.trim(obj.filepath)!=''){
	    				var addhtml = '<img src="{0}" />'.format(obj.filepath);		    	    			
	    				$("#slider").append(addhtml);
	    			}
	    		});
	    		
	    		$('#slider').nivoSlider({
		        	//manualAdvance:true
		        	 effect: 'random',               // 过渡效果  
		             slices: 15,                     // 切片效果时的数量  
		             boxCols: 8,                     // 格子效果时的列数  
		             boxRows: 4,                     // 格式效果时的行数  
		             animSpeed: 500,                // 图片过渡时间  
		             pauseTime: 10000,                // 图片显示时间  	           
		             directionNav: false,             // 是否显示图片方向切换按钮（上一页/下一页）  
		             controlNav: false,               // 是否显示图片导航控制按钮（,2,3... ）  
		             controlNavThumbs: false,        // 是否使用图片的缩略图做为导航控制按钮  
		             pauseOnHover: true,             // 鼠标县浮时是否停止动画  
		             manualAdvance: false,           // 是否手动切换  	           
		             randomStart: false,             // 开始图片是否随机		          
		        });
	    	}	
	    },  
	     error : function() {  
	         
	     }  
	});	
	
	//图片新闻
	$.ajax({  
		type: "POST",  
        url: 'SiteIndex/queryArticle.json',
	    data:{		    	    	  
	    	  isHomePic:1,
	    	  topNum:6
	    },  		    	     
	    cache:false,  
	    dataType:'json',  
	    success:function(data) { 
	    	if(data!=null && data.length>0){		    	    		
	    		$.each(data,function(idx,obj){
	    			var maxwidth=25; 
	    			if(obj.title.length>maxwidth){
	    				obj.title=obj.title.substring(0,maxwidth);
	    				obj.title+=' ...';  
	    			}	    			
	    			var url=$ctx+'SiteIndex/article.htm?id='+encode64((obj.id).toString());	    			
	    			var addhtml = '<a href="'+url+'">' +
    						         '<img src="'+obj.imagesPath.split(',').shift()+'"  title="'+obj.title+'" />' +
    						      '</a>';
	                $("#picnews").append(addhtml);	    	                
	    		});
	    		
	    		$('#picnews').nivoSlider({	    		    			 
					 directionNav: false, //是否显示图片切换按钮(上/下页)
					 directionNavHide: true, //是否鼠标经过才显示
		        	 controlNav: true,               // 是否显示图片导航控制按钮（,2,3... ）  
		             pauseOnHover: true            // 鼠标县浮时是否停止动画 
		        });			    	    		
	    	}	
	    },  
	     error : function() {  
	          
	     }  
	});
	
	
	
	//友情链接
	$.ajax({  
		type: "POST",  
        url: 'SiteIndex/querySiteLink.json', 
	    data:{  
	    	  visible:1,
	    	  //typeid:1 //文字链接
	    },  		    	     
	    cache:false,  
	    dataType:'json',  
	    success:function(data) { 
	    	if(data!=null && data.length>0){		    	    		
	    		$.each(data,function(idx,obj){
	    			var addhtml = '<li><a target="_blank" href="{0}">{1}</a>|</li>'.format(obj.link,obj.title);
	    			if(idx==data.length-1){
	    				addhtml = '<li><a target="_blank" href="{0}">{1}</a></li>'.format(obj.link,obj.title);
	    			}
	                $("#links").append(addhtml);		    	                
	    		});
	    	}	
	    },  
	     error : function() {  
	          
	     }  
	});
	
	

});



function buttonClick(forword_url)
{
	window.open(forword_url);
}
/**
 * 获邓专题。
 */
function querySubjectTopic()
{	
	$.ajax({  
		type: "POST",  
        url: 'WebSubject/querySubjectTopic.json',  
        data:{  
        	is_publish:1,		    	    	  
	    },  
	    cache:false,  
	    dataType:'json',  
	    success:function(data) { 
	    	if(data!=null && data.length>0){
	    		$.each(data,function(idx,e){	
	    			var linkpath = "";
	    			if(e.islink ==0){
	    				linkpath=e.link_url;
	    			}else{
	    				linkpath="WebSubject/subjectMain.htm?id="+e.id;
	    			}	    			
	    			var addhtml = '<div class="item"><a target="_blank"  href="javascript:void(0);" onclick="buttonClick(\''+linkpath+'\');return false;" ><img src="'+e.title_image+'" /></a></div>';	  
	    			if(idx==data.length-1){
	    				addhtml = '<div class="item"><a target="_blank" style="margin-right:0px;"  href="javascript:void(0);"   onclick="buttonClick(\''+linkpath+'\'); return false;"  ><img src="'+e.title_image+'" /></a></div>'; 
	    	    	} 		
	    			
	    			$("#owl-demo").append(addhtml);
	    		});
	    		
	    		$('.owl-carousel').owlCarousel({
	    		    loop:true,
	    		    margin:10,
	    		    nav:true,
	    		    navText: ['', ''],
	    		    dots:false,				   
	    		    responsive:{
	    		        0:{
	    		            items:1
	    		        },
	    		        600:{
	    		            items:2
	    		        },
	    		        1000:{
	    		            items:3
	    		        }
	    		    }
	    		});
	    		
	    	}	
	    },  
	     error : function() {  
	          
	     }  
	});
}



//查找文章
function queryArticleList(categoryId,ulId,isTop){
	var listNum=6;
	if(isTop=='1'){
		listNum=5;
	}
	
	$.ajax({  
		type: "POST",  
        url: 'SiteIndex/queryArticle.json', 
	    data:{  
	    	  categoryID:categoryId,	
	    	  topNum:listNum
	    },  		    	     
	    cache:false,  
	    dataType:'json',  
	    success:function(data) { 
	    	if(data!=null && data.length>0){		    	    		
	    		$.each(data,function(idx,obj){
	    			if(idx==0 && isTop=='1'){ // 头条新闻	    			
	    				var tophtml=topArticle(obj);	    				
	    				$("#"+ulId).append(tophtml);
	    			}else{
	    				var maxwidth=25; 
	    				if(obj.title.length>maxwidth){
		    				obj.title=obj.title.substring(0,maxwidth);
		    				obj.title+=' ...'; 
		    			}
	    				
		    			var url=$ctx+'SiteIndex/article.htm?id='+encode64((obj.id).toString());
		    			
		    			var addhtml = '<li><a target="_blank" style="color:'+obj.titleColor+'" href="'+url+'">'+obj.title+'</a>'+
	    							      '<span class="date">'+new Date(obj.modifyDate).format("yyyy-MM-dd")+'</span>'+
	    						      '</li>';
		    			 $("#"+ulId).append(addhtml);
	    			}	                
	    		});
	    		
	    		if(data.length==listNum){
	    			var moreUrl=$ctx+'SiteIndex/category.htm?id='+encode64((categoryId).toString());	
	    			
		    		//var moreHtml='<a class="amore" href="'+moreUrl+'" >更多&nbsp;&gt;&gt;</a>';
		    	    //$("#"+ulId).nextAll(".more").html(moreHtml); 
		    	    
	    		}
	    	}	
	    },  
	     error : function() {  
	          
	     }  
	});
}

// 查找头条文章 
function topArticle(article){	
	var tophtml='';	
	$.ajax({  
		type: "POST",  
        url: 'SiteIndex/queryArticleById.json', 
	    data:{  
	    	id:article.id	    	  
	    },  		    	     
	    cache:false,  
	    async: false, //同步
	    dataType:'json',  
	    success:function(data) { 	       	   	
	    	if(data.id!=null){
	    		var maxwidth=25; 
				if(data.title.length>maxwidth){
					data.title=data.title.substring(0,maxwidth);
					data.title+=' ...'; 
    			}	    	
				
				var maxcontent=105; 
				if(data.contents!=null && data.contents.length>maxwidth){
					data.contents=data.contents.substring(0,maxcontent);
					data.contents+=' ...'; 
    			}				
    			var url=$ctx+'SiteIndex/article.htm?id='+encode64((data.id).toString());
    	    		
    			tophtml = '<li id="topArticle"><span>'+data.title+'</span>'+
    					      '<p>'+data.contents+'</p>'+
						      '<a target="_blank" href="'+url+'">【 详细 】</a>'+
						  '</li>';	    		
	    	}	
	    },  
	     error : function() {  
	         
	     }  
	});
	
	return tophtml;
	
	
}


function queryAdPic(typeId,divID){
	//行政概况--数据服务
	$.ajax({  
		type: "POST",  
        url: 'SiteIndex/querySiteAd.json', 
	    data:{  
	    	  visible:0,
	    	  typeid:typeId //行政概况
	    },  		    	     
	    cache:false,  
	    dataType:'json',  
	    success:function(data) { 
	    	if(data!=null && data.length>0){		    	    		
	    		$.each(data,function(idx,obj){	    	    			
	    			var addhtml = '<li><a target="_blank" href="{0}"><img src="{1}" />{2}</a></li>'.format(obj.link,obj.filepath,obj.title);	    			
	                $("#"+divID).append(addhtml);		    	                
	    		});
	    	}	
	    },  
	     error : function() {  
	          
	     }  
	});
}

//政民互动
function queryAdPicForA(typeId,divID){	
	$.ajax({  
		type: "POST",  
        url: 'SiteIndex/querySiteAd.json', 
	    data:{  
	    	  visible:0,
	    	  typeid:typeId 
	    },  		    	     
	    cache:false,  
	    dataType:'json',  
	    success:function(data) { 
	    	if(data!=null && data.length>0){		    	    		
	    		$.each(data,function(idx,obj){	
	    			var className='';
	    			var title=obj.title;
	    			if(title!='' && title.indexOf('&')!=-1){
	    				className=title.substring(title.indexOf('c'));
	    				title=title.substring(0,title.indexOf('&'));
	    			}	    			
	    			var addhtml = '<a target="_blank" href="'+obj.link+'"><img '+className+' src="'+obj.filepath+'"/>'+title+'</a>';	    			
	                $("#"+divID).append(addhtml);		    	                
	    		});
	    	}	
	    },  
	     error : function() {  
	         
	     }  
	});
}
//投诉举报
function queryAdPicForTs(typeId,divID){
	
	$.ajax({  
		type: "POST",  
        url: 'SiteIndex/querySiteAd.json', 
	    data:{  
	    	  visible:0,
	    	  typeid:typeId 
	    },  		    	     
	    cache:false,  
	    dataType:'json',  
	    success:function(data) { 
	    	if(data!=null && data.length>0){		    	    		
	    		$.each(data,function(idx,obj){
	    			var addhtml="";
	    			if(obj.link!=null && obj.link!=""){
	    				addhtml = '<li><a target="_blank" style="line-height: 53px; color:red;font-size:15px;" href="'+obj.link+'"><img src="'+obj.filepath+'" style="margin-right:0px;"/>'+(obj.description).replace(/\n/g,'');+'</a></li>';	
	    			}else{
	    				addhtml = '<li><img src="'+obj.filepath+'"/>'+(obj.description).replace(/\n/g,'<br/>');+'</li>';	
	    			}
	    			   $("#"+divID).append(addhtml);		    	                
	    		});
	    	}	
	    },  
	     error : function() {  
	         
	     }  
	});
}

function timeStamp2String(time,geshi){  
    var datetime = new Date();  
    datetime.setTime(time);  
    var year = datetime.getFullYear();  
    var month = datetime.getMonth() + 1 < 10 ? "0" + (datetime.getMonth() + 1) : datetime.getMonth() + 1;  
    var date = datetime.getDate() < 10 ? "0" + datetime.getDate() : datetime.getDate();  
    var hour = datetime.getHours()< 10 ? "0" + datetime.getHours() : datetime.getHours();  
    var minute = datetime.getMinutes()< 10 ? "0" + datetime.getMinutes() : datetime.getMinutes();  
    var second = datetime.getSeconds()< 10 ? "0" + datetime.getSeconds() : datetime.getSeconds();  
    if(geshi=="1"){
    	 return year + "-" + month + "-" + date+" "+hour+":"+minute;  
    }else if(geshi=="2"){
    	return year + "-" + month + "-" + date;  
    }else if(geshi=="3"){
    	 return date+"日"+hour+"时"; 
    }
}

//格式化日期
Date.prototype.format = function(format) {
    var o = {
        "M+": this.getMonth() + 1, // month
        "d+": this.getDate(), // day
        "h+": this.getHours(), // hour
        "m+": this.getMinutes(), // minute
        "s+": this.getSeconds(), // second
        "q+": Math.floor((this.getMonth() + 3) / 3), // quarter
        "S": this.getMilliseconds()
        // millisecond
    }
    if (/(y+)/.test(format))
        format = format.replace(RegExp.$1, (this.getFullYear() + "")
            .substr(4 - RegExp.$1.length));
    for (var k in o)
        if (new RegExp("(" + k + ")").test(format))
            format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
    return format;
}

//base64加密开始
var keyStr = "ABCDEFGHIJKLMNOP" + "QRSTUVWXYZabcdef" + "ghijklmnopqrstuv" + "wxyz0123456789+/" + "=";

function encode64(input) {
        var output = "";
        var chr1, chr2, chr3 = "";
        var enc1, enc2, enc3, enc4 = "";
        var i = 0;
        do {
                chr1 = input.charCodeAt(i++);
                chr2 = input.charCodeAt(i++);
                chr3 = input.charCodeAt(i++);
                enc1 = chr1 >> 2;
                enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
                enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
                enc4 = chr3 & 63;
                if (isNaN(chr2)) {
                        enc3 = enc4 = 64;
                } else if (isNaN(chr3)) {
                        enc4 = 64;
                }
                output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2)
                                + keyStr.charAt(enc3) + keyStr.charAt(enc4);
                chr1 = chr2 = chr3 = "";
                enc1 = enc2 = enc3 = enc4 = "";
        } while (i < input.length);

        return output;
}
// base64加密结束



